#include "stdafx.h"
#include "Math.h"

NAMESPACE_CORE_BEGIN

CSizeInt32 SiseInt32FromInt32(int_32 iVal)
{
	return SiseInt32FromUInt32((uint_32)iVal);
}

CSizeInt32 SiseInt32FromUInt32(uint_32 uiVal)
{
	return CSizeInt32((int_32)(uiVal & 0xFFFF), (int_32)(uiVal >> 16));
}

CSizeInt32 SiseInt32FromInt64(int_64 iVal)
{
	return SiseInt32FromUInt64((uint_32)iVal);
}

CSizeInt32 SiseInt32FromUInt64(uint_64 uiVal)
{
	return CSizeInt32((int_32)(uiVal & 0xFFFFFFFF), (int_32)(uiVal >> 32));
}

CSizeInt32 SiseInt32FromIntX(int_x iVal)
{
#ifdef BIT_64
	return SiseInt32FromInt64(iVal);
#else
	return SiseInt32FromInt32(iVal);
#endif
}
CSizeInt32 SiseInt32FromUIntX(uint_x uiVal)
{
#ifdef BIT_64
	return SiseInt32FromUInt64(uiVal);
#else
	return SiseInt32FromUInt32(uiVal);
#endif
}

CPointInt32 PointInt32FromInt32(int_32 iVal)
{
	return PointInt32FromUInt32((uint_32)iVal);
}
CPointInt32 PointInt32FromUInt32(uint_32 uiVal)
{
	return CPointInt32((int_32)(uiVal & 0xFFFF), (int_32)(uiVal >> 16));
}
CPointInt32 PointInt32FromInt64(int_64 iVal)
{
	return PointInt32FromUInt64((uint_32)iVal);
}
CPointInt32 PointInt32FromUInt64(uint_64 uiVal)
{
	return CPointInt32((int_32)(uiVal & 0xFFFFFFFF), (int_32)(uiVal >> 32));
}
CPointInt32 PointInt32FromIntX(int_x iVal)
{
#ifdef BIT_64
	return PointInt32FromInt64(iVal);
#else
	return PointInt32FromInt32(iVal);
#endif
}

CPointInt32 PointInt32FromUIntX(uint_x uiVal)
{
#ifdef BIT_64
	return PointInt32FromUInt64(uiVal);
#else
	return PointInt32FromUInt32(uiVal);
#endif
}

int_32 RoundUp(float_32 fVal)
{
	int_32 iVal = (int_32)fVal;
	fVal -= iVal;
	if(fVal > F32_EPSILON)
		++iVal;
	return iVal;
}
int_32 Round(float_32 fVal)
{
	int_32 iVal = (int_32)fVal;
	fVal -= iVal;
	if(fVal > 0.5f)
		++fVal;
	return iVal;
}
int_32 RoundDown(float_32 fVal)
{
	return (int_32)fVal;
}
bool Float32Equal(const float_32 & fa, const float_32 & fb)
{
	float_32 fc = fa - fb;
	return (fc > -F32_EPSILON) && (fc < F32_EPSILON);
}
NAMESPACE_CORE_END
